package com.crr.controller;



import cn.hutool.core.date.DateUtil;
import com.crr.apis.PayFeignApi;
import com.crr.entities.PayDTO;
import com.crr.ret.ResultData;
import com.crr.ret.ReturnCodeEnum;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/feign")
public class OrderController {
    @Resource
    private PayFeignApi payFeignApi;

    @PostMapping("/pay/add")
    public ResultData addOrder(@RequestBody PayDTO payDTO) {
        return payFeignApi.addPay(payDTO);
    }

    @GetMapping("/pay/get/{id}")
    public ResultData getPayInfo(@PathVariable("id") Integer id) {
        System.out.println("-----------支付微服务远程调用，按照id查询订单支付流水账单");
        ResultData resultData=null;
        try {
            System.out.println("-----------调用开始"+ DateUtil.now());
          resultData = payFeignApi.getById(id);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("=========调用结束"+DateUtil.now());
            ResultData.fail(ReturnCodeEnum.RC500.getCode(), e.getMessage());
        }
        return resultData;
    }

    /**
     * 天然支付负载均衡演示
     * @return
     */
    @GetMapping("/pay/info")
    public String mylb(){
        return payFeignApi.mylb();
    }
}
